import {createPushRoom} from './listItem/service';
import {getQuery, getPointer} from '../../utils/Av';
import groupBy from 'lodash.groupby';
import Map from 'lodash.map';
export async function getAddFriends () {
  var currentuser = AV.User.current ();
  console.log (currentuser);
  var q1 = getQuery ('friend').equalTo (
    'to',
    getPointer ('_User', currentuser.toJSON ().objectId)
  );
  q1.include ('from');
  var users = await q1.include ('from').find ().then (res =>
    res.map (item => {
      var __item = item.toJSON ().from;
      __item.id = item.toJSON ().from.objectId;
      __item.name = item.toJSON ().from.username;
      __item.avatar = item.toJSON ().from.avatar;
      return __item;
    })
  );

  var _users = groupBy (users, item =>{
    var one=(item.username || item.mobilePhoneNumber)[0]
    return pinyinUtil.getFirstLetter (one)
  });
  var _user2 = Map (_users, (item, key) => {
    var __item = {title: '', items: []};
    __item.title = key;
    __item.items = item;
    return __item;
  });

  return _user2;
}
